import re
import os

def find_vue_files(folder_path):
    vue_files = []
    for root, dirs, files in os.walk(folder_path):
        for file in files:
            if file.endswith('.vue'):
                vue_files.append(os.path.join(root, file))
    return vue_files

def extract_image_paths(file_path):
    with open(file_path, 'r', encoding='utf-8') as f:
        content = f.read()
    
    # 匹配引号/括号内的图片路径（包括别名如@/assets/）
    pattern = r'''
        (?:url$|src=|require\(|['"])  # 匹配起始符号
        ([^'"$]+?\.(?:png|jpg|jpeg|gif|svg|webp))  # 匹配路径和扩展名
        (?:['"\)])  # 匹配结束符号
    '''
    matches = re.findall(pattern, content, re.VERBOSE | re.IGNORECASE)
    return matches

def resolve_alias(image_path):
    if image_path.startswith('@/'):
        return image_path.replace('@', 'src', 1)
    return image_path

def main(target_folder):
    vue_files = find_vue_files(target_folder)
    all_images = set()
    
    for vue_file in vue_files:
        images = extract_image_paths(vue_file)
        for img in images:
            resolved_path = resolve_alias(img)
            all_images.add(resolved_path)
    
    print("Vue文件中使用的图片路径：")
    for path in all_images:
        print(f"- {path}")

if __name__ == '__main__':
    main('D:\\Code\\Xt-visSys-Frontend')  # 替换为实际路径
